package com.lzm.ydpt.module.mall.activity;

import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;

import com.byt.framlib.base.BaseActivity;
import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.commonwidget.NormalTitleBar;
import com.byt.framlib.commonwidget.OnNoDoubleClickListener;
import com.byt.framlib.commonwidget.badgeview.QBadgeView;
import com.byt.framlib.commonwidget.onclicktwo.AntiShake;
import com.lzm.ydpt.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 消息中心
 */
public class MessageCenterActivity extends BaseActivity {
    @BindView(R.id.ntb_message_center)
    NormalTitleBar ntb_message_center;
    @BindView(R.id.img_show_action_num)
    ImageView img_show_action_num;
    @BindView(R.id.img_show_order_num)
    ImageView img_show_order_num;
    QBadgeView actionView;
    QBadgeView orderView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_message_center;
    }

    @Override
    public BasePresenter initPreData() {
        return null;
    }

    @Override
    public void initView() {
        setNtbTitle(ntb_message_center, false);
        ntb_message_center.setTitleText("消息中心");
        ntb_message_center.setOnBackListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
        setActionoNum(4);
        setOrderNum(2);
    }

    private void setActionoNum(int num) {
        if (actionView == null) {
            actionView = new QBadgeView(this);
            actionView.bindTarget(img_show_action_num)
                    .setBadgeTextSize(8, true)
                    .setBadgeGravity(Gravity.CENTER);
        }
        actionView.setBadgeNumber(num);
    }

    private void setOrderNum(int num) {
        if (orderView == null) {
            orderView = new QBadgeView(this);
            orderView.bindTarget(img_show_order_num)
                    .setBadgeTextSize(8, true)
                    .setBadgeGravity(Gravity.CENTER);
        }
        orderView.setBadgeNumber(num);
    }

    @OnClick({R.id.rl_order_msg, R.id.rl_discount_message_center})
    public void onClick(View view) {
        if (AntiShake.check(view.getId())) {
            return;
        }
        switch (view.getId()) {
            case R.id.rl_order_msg:
                openActivity(OrderMsgActivity.class);
                break;
            case R.id.rl_discount_message_center:
                openActivity(DiscountActionActivity.class);
                break;
        }
    }
}
